(function( $ ) {
	var methods = {
		getRange: function() {
			if (window.getSelection) {
				var selObj = window.getSelection();
				if(selObj.rangeCount > 0) {
					var rage = selObj.getRangeAt(0);
					return {start: rage.startOffset, end: rage.endOffset, contentLength: rage.startContainer.length};
				}
			}
			else if (document.selection) {
				var range = document.selection.createRange();
				var bookmark = range.getBookmark();
				/* FIXME the following works wrong when the document is longer than 65535 chars */
				cursorPos = bookmark.charCodeAt(2) - 11; /* Undocumented function [3] */
			}

			return {start: 0, end: 0, contentLength: this.html().length };
		},
		selectAll: function() {
			if(window.getSelection) {
				var selObj = window.getSelection();
				selObj.selectAllChildren(this[0]);
			}
			else if(document.selection) {
				//TODO: Legacy IE support.
			}
		},
		setCarot: function(loc) {
			if(window.getSelection) {
				var selObj = window.getSelection();
				selObj.removeAllRanges();
				var rage = document.createRange();
				rage.selectNodeContents(this[0]);
				if(rage.startContainer.childNodes.length > 0) {
					var rage2 = document.createRange();
					if(loc == 'end') {
						var pos = $(rage.endContainer).html().length;
						rage2.setStart(rage.endContainer.childNodes[0], pos);
						rage2.setEnd(rage.endContainer.childNodes[0], pos);
					}
					else {
						rage2.setStart(rage.startContainer.childNodes[0], 0);
						rage2.setEnd(rage.startContainer.childNodes[0], 0);
					}
					selObj.addRange(rage2);
				}
			}
			else if(document.selection) {
				//TODO: Legacy IE support.
			}
		}
	};
	$.fn.selectedRange = function(method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.articleListDisplay');
        }
	}
})(jQuery);